package com.news.db;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.content.Context;

public class DBUtil {
	MyDBAdapter db;
	
	public DBUtil(Context context) {
		db = new MyDBAdapter(context);
	}
	
	/**
	 * 插入文章列表
	 */
	public void insertTittleList(List<Map<String, Object>> tittle_List, String columnid) {
		db.open();
		db.insertTitle(tittle_List , columnid);
		db.close();
	}
	
	/**
	 * 向数据库更新已读标记
	 */
	public void setContentIsRead(String url) {
		db.open();
		db.setIsRead(url);
		db.close();
	}
	
	/**
	 * 插入文章内容
	 * @param table
	 * @param nullColumnHack
	 * @param values
	 */
	public void updateContent(String url, String content) {
		db.open();
		db.updateContent(url, content);
		db.close();
	}
	
	/**
	 * 根据栏目ID获取文章列表
	 * 
	 * @return
	 */
	public List<Map<String, Object>> getTitleFromDB(String columnid) {
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		db.open();
		try {

			list = db.getTitleFromDB(columnid);
		} finally {
			db.close();
		}
		return list;
	}
	
	/**
	 * 根据url查询文章内容
	 */
	
	public String qurryContentByUrl(String url) {
		String content;
		db.open();
		try {
			content = db.qurryContentByUrl(url);
		} finally {
			db.close();
		}
		return content;
	}
	
}
